package Sort;

import java.awt.geom.CubicCurve2D;
import java.security.acl.Permission;

import util.MathMethod;
import DataStructure.MyMaxHeapForHeapSort;
import DataStructure.MyMinHeapForHeapSort;

public class HeapSort {
	public static void maxHeapSort(int[] a){
		MyMaxHeapForHeapSort myHeap = new MyMaxHeapForHeapSort(a);
		for(int i = a.length; i >= 1;i--){
			//MathMethod.exchangEach(myHeap.array[1],myHeap.array[i]);
			int tmp = myHeap.array[i];
			myHeap.array[i] = myHeap.array[1];
			myHeap.array[1] = tmp;
			myHeap.currentSize -= 1;
			myHeap.percolateDown(1);
		}
		System.out.println();
		for (int i = 1; i <= a.length; i++) {
			System.out.print(myHeap.array[i]+"-->");
		}
	}
	public static void minHeapSort(int[] a){
		MyMinHeapForHeapSort myHeap = new MyMinHeapForHeapSort(a);
		for(int i = a.length;i >= 1; i--){
			int tmp = myHeap.array[1];
			myHeap.array[1] = myHeap.array[myHeap.currentSize];
			myHeap.array[myHeap.currentSize] = tmp;
			myHeap.currentSize -= 1;
			myHeap.percolateDown(1);
		}
		System.out.println();
		for (int i = 1; i <= a.length; i++) {
			System.out.print(myHeap.array[i]+"-->");
		}
	}
}
